<template>
	<view class="custom-bar" :style="[{height:customBar + 'px'}]">
		<view class="container" :style="style" :class="bgImageUrl!=''?'text-white bg-img':''">
			<!-- 左侧 -->
			<view class="left" :style="[{top:statusBar + 'px'}]">
				<view class="back" v-if="isBack">
					<text class="iconfont icon-fanhui" @click="toBack"></text>
				</view>
				<slot name="left"></slot>
			</view>
			<!-- 中间 -->
			<view class="content" :style="[{top:statusBar + 'px'}]">
				<slot name="content"></slot>
			</view>

		</view>
	</view>
</template>

<script>
	export default {
		name: "nav-bar",
		data() {
			return {
				statusBar: this.StatusBarHeight,
				customBar: this.CustomBarHeight
			};
		},
		computed: {
			style() {
				var statusBar = this.statusBar;
				var customBar = this.customBar;
				var bgImage = this.bgImageUrl;
				var bgColor = this.bgColor;
				var style = `height:${customBar}px;padding-top:${statusBar}px;`;
				if (this.bgImageUrl) {
					style = `${style}background-image:url(${bgImage});`;
				} else {
					style = `${style}background-color:${bgColor};`;
				}
				return style
			}
		},
		props: {
			bgColor: {
				type: String,
				default: ''
			},
			isBack: {
				type: [Boolean, String],
				default: false
			},
			bgImageUrl: {
				type: String,
				default: ''
			},
		},
		methods: {
			toBack() {
				uni.navigateBack()
			}
		}
	}
</script>

<style lang="scss">
	.custom-bar {
		width: 100%;
		display: block;
		position: relative;

		.container {
			width: 100%;
			position: fixed;
			top: 0;
			z-index: 9999;

			.left {
				position: absolute;
				left: 0;
				bottom: 0;
				display: flex;
				z-index: 100;
				align-items: center;
				justify-content: center;

				.back {
					margin: 18rpx 28rpx;
					font-weight: bold;
					font-size: 33rpx;
				}
			}

			.content {
				position: absolute;
				bottom: 0;
				width: 100%;
				z-index: 99;
				display: flex;
				align-items: center;
				justify-content: center;
			}
		}

		.bg-img {
			background-size: cover;
			background-position: center;
			background-repeat: no-repeat;
		}
	}
</style>
